<?php
/**
 * @todo 右边分类小组件
 * @author shenjun
 */
class Category extends CWidget{
	
	public function run(){
//		var_dump(new Category());exit();

		$language = strtoupper( Yii::app()->session->offSetGet( "FrontLanguage" ) );
		$list = $language === 'EN' ? '' : '';
		if($_GET['r']=='site/aboutus'){
			$typeAry=Yii::app()->params[$language.'aboutusType'];
			echo '<div class="title1">' , $list , '</div>
					<ul>';			
			foreach ( $typeAry as $key=>$value ){
				echo '<li><a href="' , Yii::app()->controller->createUrl("site/aboutus#".$key) , '">', $value ,'</a></li>';
			}			
		}else{
			$db = Yii::app()->db;
			$sql = 'SELECT * FROM {{category}} WHERE Flag=1 AND ParentID=0';
			$datas = $db->createCommand( $sql )->queryAll();
			$listUrl = 'site/prodlist' ;
			echo '<div class="title1">' , $list , '</div>
					<ul>';
			if ( is_array( $datas ) ){
				foreach ( $datas as $value ){
					echo '<li><a href="' , Yii::app()->controller->createUrl( $listUrl , array( 'CaID' => $value['ID'] ) ) , '">', $value[ $language.'Name' ] ,'</a>';
					$sql=" SELECT * FROM {{category}} WHERE Flag=1 AND ParentID={$value['ID']}";
					$nextCategory = $db->createCommand( $sql )->queryAll();
					if(is_array($nextCategory) && !empty($nextCategory))
					{
						echo '<ul style="display: none;">';
						foreach ($nextCategory as $NeK=>$NeV){
							echo '<li><a href="' , Yii::app()->controller->createUrl( $listUrl , array( 'CaID' => $NeV['ID'] ) ) , '">', $NeV[ $language.'Name' ] ,'</a></li>';
						}
						echo '</ul></li>';
					}else{
						echo '</li>';
					}
										
				}
			}


		}
		
			Yii::app()->clientScript->registerCssFile( Yii::app()->request->baseURL . 'css/show2cat.css');
			if($_GET['r']=='site/aboutus'){
				Yii::app()->clientScript->registerScriptFile( Yii::app()->clientScript->getCoreScriptUrl() . '/category2.js',2);
			}else{
				Yii::app()->clientScript->registerScriptFile( Yii::app()->clientScript->getCoreScriptUrl() . '/category.js',2);
			}
			Yii::app()->clientScript->registerScriptFile( Yii::app()->clientScript->getCoreScriptUrl() . '/show2cat.js');		
		
//        echo'
//            <li><a href="#">Full Colour Plastic Cards</a></li>
//            <li><a href="#">Plastic Card Options</a></li>
//            <li><a href="#">Plastic Business Cards</a></li>
//            <li><a href="#">Key Cards/Key Tags</a></li>
//            <li><a href="#">Clear Plastic Cards</a></li>
//            <li><a href="#">Custom Die Cut Cards</a></li>
//            <li><a href="#">Photo ID Cards</a></li>
//            <li><a href="#">Blank Plastic Cards</a></li>
//            <li><a href="#">Smart Cards</a></li>
//            <li><a href="#">Metal Cards</a></li>
//            <li><a href="#">Economy/Paper Cards</a></li>
//            <li><a href="#">Environmental plastic cards</a></li>
//            <li><a href="#">Hologram Labels</a></li>
//            <li><a href="#">Accessories</a></li>
//            <li><a href="#">Card Carriers</a></li>
//            <li><a href="#">Embossing machine</a></li>
//          </ul>';
	}
}